package com.bt.controller;

import com.bt.annotation.RequiresPermissionsDesc;
import com.bt.pojo.DtsGoods;
import com.bt.service.DtsGoodsService;
import com.bt.service.DtsOrderGoodsService;
import com.bt.service.DtsOrderService;
import com.bt.service.DtsUserService;
import com.bt.util.ResponseUtil;
import com.bt.vo.GoodsStmtVo;
import com.bt.vo.OrderStmtVo;
import com.bt.vo.UserDayVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wbt
 * @version v1.0
 * @project shop_manage
 * @data 2022/9/26 16:43
 **/
@RequestMapping("/admin/stat")
@RestController
@CrossOrigin
public class AdminStatController {
    @Autowired
    private DtsUserService userServiceImpl;
    @Autowired
    private DtsOrderService orderServiceImpl;
    @Autowired
    private DtsOrderGoodsService orderGoodsServiceImpl;
    /**
     * http://localhost:8083/admin/stat/user
     * get
     *
     */

    @GetMapping("/user")
    @RequiresPermissions("admin:stat:user")
    @RequiresPermissionsDesc(menu = {"统计管理", "用户统计"}, button = "查询")
    public Object user() {
        List<UserDayVo> userDayVos = userServiceImpl.findUserDayVos();
        Map map=new HashMap<>();
        map.put("columns",new String[]{"day", "users"});
        map.put("rows",userDayVos);
        return ResponseUtil.ok(map);
    }
    /**
     * http://localhost:8080/admin/stat/order
     * get
     * day: 日期,  orders : 订单量, customers : 下单用户数,  amount : 订单总额,  pcr: 客单价(平均单价)
     */
    @GetMapping("/order")
    @RequiresPermissions("admin:stat:order")
    @RequiresPermissionsDesc(menu = {"统计管理", "订单统计"}, button = "查询")
    public Object order() {
        List<OrderStmtVo> OrderStmtVos = orderServiceImpl.findOrderStmtVos();
        Map map=new HashMap<>();
        map.put("columns",new String[]{"day", "orders","customers","amount","pcr"});
        map.put("rows",OrderStmtVos);
        return ResponseUtil.ok(map);
    }
    /**
     * http://localhost:8080/admin/stat/goods
     * get
     * day : 日期, orders : 订单量,  products : 下单货品数量 , amount : 下单货品总额
     */
    @GetMapping("/goods")
    @RequiresPermissions("admin:stat:goods")
    @RequiresPermissionsDesc(menu = {"统计管理", "商品统计"}, button = "查询")
    public Object goods() {
        List<GoodsStmtVo>  goodsStmtVoList=orderGoodsServiceImpl.findStmtVos();
        Map data=new HashMap();
        data.put("columns",new String[]{"day", "orders","products","amount"});
       data.put("rows",goodsStmtVoList);
        return ResponseUtil.ok(data);
    }
}
